﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict.DataModel;


namespace Dict.Blo
{
    public class DictEquipRefineBlo
    {
        public static TableEquipRefine GetTableEquipRefine(int type,int quality)
        {
            List<TableEquipRefine> list = Dict.DictDataManager.Instance.tableEquipRefineDao.GetByTwoIndex(type,quality);
            if (list.Count > 0)
                return list[0];

            return null;
        }

        public static List<TableEquipRefineExp> GetEquipRefineExpList(int quality)
        {
            return Dict.DictDataManager.Instance.tableEquipRefineExpDao.GetByOneIndex(quality);
        }

        public static int GetEquipRefineExp(int quality,int level)
        {
            if(level <= 0)
            {
                return 0;
            }
            List<TableEquipRefineExp> list = Dict.DictDataManager.Instance.tableEquipRefineExpDao.GetByOneIndex(quality);
            return list[level - 1].refineExp;
        }
        
        public static int GetEquipRefineMaxLevel(int quality)
        {
            List<TableEquipRefineExp> list = Dict.DictDataManager.Instance.tableEquipRefineExpDao.GetByOneIndex(quality);
            return list.Count;
        }

        public static int GetEquipPredictRefineLevelWithExp(int quality,int level,int exp)
        {
            List<TableEquipRefineExp> list = Dict.DictDataManager.Instance.tableEquipRefineExpDao.GetByOneIndex(quality);
            int totalExp = exp;
            int predictLv = level;
            for(int i = level; i < list.Count; i++)
            {
                if(totalExp >= list[i].refineExp)
                {
                    totalExp -= list[i].refineExp;
                    predictLv = i + 1;    
                }
                else
                {
                    break;
                }
            }
            return predictLv;
        }
    }
}